<%@ page pageEncoding="UTF-8" contentType="text/html; charset=UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<!DOCTYPE html>

<html>
    <head>
		<%@ include file="/WEB-INF/views/include/common.jsp" %>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<meta name="AUTHOR" content="QroTech Inc." />
		<meta http-equiv="CACHE-CONTROL" content="NO-CACHE">
		<meta http-equiv="PRAGMA" content="NO-CACHE">
		<meta name="ROBOTS" content="NOINDEX, NOFOLLOW">
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
		<title>큐로넷::위치관제시스템</title>
		
		<link rel="stylesheet" href="${cssUrl}/header-1.css" type="text/css" />
		<link rel="stylesheet" href="${cssUrl}/fancy_table.css" type="text/css" />
		<link rel="stylesheet" href="${cssUrl}/menu.css" type="text/css" />
		<link rel="stylesheet" href="${cssUrl}/table.css" type="text/css" />
		<link rel="stylesheet" href="${cssUrl}/button.css" type="text/css" />
		<link rel="stylesheet" href="${cssUrl}/m-300.css" type="text/css" />
		<link rel="stylesheet" href="${cssUrl}/m-310.css" type="text/css" />
		<script src="${jsUrl}/m-310.js"></script>
		
		<style>
		#map_canvas { height: 80% }
		</style>
		<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?key=AIzaSyCjYzALnSN1zEr2CcvzGGwFxBylVDpFcCI&sensor=false"></script>
    </head>
    <body onload="init()">
    	<div id="overlay" class="overlay" >
    	</div><!-- contentWrapper end -->
    	<div class="headerContent">
	
		<div class="pageHeader">
			<%@ include file="/WEB-INF/views/include/logoLink.jsp" %>
			<div id="pageNav">
				<ul>
<!-- 					<a href="/totalCarListMain" class="togglerHeader"><li class="hmenu0" id="hdmenu0"></li></a> -->
<!-- 					<a href="#" class="togglerHeader"><li class="hmenu1" id="hdmenu1"></li></a> -->
<!-- 					<a href="m-300.html" class="togglerHeader"><li class="hmenu2" id="hdmenu2"></li></a> -->
<!-- 					<a href="#" class="togglerHeader"><li class="hmenu3" id="hdmenu3"></li></a> -->
					<%@ include file="/WEB-INF/views/include/mainNaviStyle2.jsp" %>
				</ul>
			</div>
			<div id="pageNavRight">
				<%@ include file="/WEB-INF/views/include/titleLink.jsp" %>
			</div>
		</div>
			<div class="header_line"></div>
		</div><!--header end-->	
	
        
        	<div class="secondMenu" >
					<div id="menu">
						<ul>
							<%@ include file="/WEB-INF/views/include/innerNavi.jsp" %>
						</ul>
					</div>
						
				</div><!-- second menu end -->
			<div class="m310height">
				
			
			<div class="mainContent310">
				<div class="searchInfo">
					<ul>
						<li class= "locationInfo"><span>관심지역관리</span><span class="colorRed">왼쪽 테이블의 관심지역을 선택하여 조회 및 수정합니다.</span><span class="colorRed">등록한 관심지역은 회사내의 전체 사용자에 의해 조회가 가능합니다.</span></li>
						
					</ul>
					<div class="last"><a onclick="javscript:openQuestionPopup('http://www.qronet.co.kr/help/qronet_help.html#MonitoringArea')"><img src="${imgUrl}/question_mark.png"></a></div>
				</div><!-- searchInfo end -->
				<div class="topLeftAndRight">
					<div class="topLeftAndRightContent">
						<div class="topLeft">
							<div class="topLeftContent">
								<div class="chart300">
									<div class="chart_head" >
										<table  valign="top" cellpadding="0" cellspacing="0"> 
											<tr valign="top" >												
												<th width="30px">사용</th>
												<th width="85px">관심지역명</th>
												<th width="170px">위치</th>
												<th width="60px">감지반경</th>
												<th width="80px">수정일</th>
												<th width="*">SMS 알림</th>
											</tr>	
										</table>
								</div><!--chart_head end-->
								<div class="chart_body">
									<table cellpadding="0" cellspacing="0" id="checkAreaList"> 
										<tr valign="top" onClick="setData(this)">
											<td width="30px"><input type="checkbox" id="use" value="y" onClick="updateUseYN(this)"></td>
											<td width="85px" id="name"></td>
											<td width="170px" id="address"></td>
											<td width="60px" id="radius"></td>
											<td width="80px" id="modifyDate"></td>
											<td width="*" id="noti"></td>
											<td style="display:none;"><input type="hidden" id="checkAreaCode">
																	  <input type="hidden" id="smsnoti1">
																	  <input type="hidden" id="smsnoti2">
																	  <input type="hidden" id="smsnoti3">
																	  <input type="hidden" id="useYn">
											</td>											
										</tr>
									</table>	
								</div><!-- chart_body end -->
							</div><!-- chart300 end-->
							</div><!--topLeftContent end -->
						</div><!--topLeft end -->
						<div class="topRight">
							<div class="topRightContent">
								<div class="top">
									<span class="plate">관심지역명 </span>
									<span class="plate">진출입 히스토리</span>
								</div>
								<div class="chart300">
									<div class="chart_head" >
										<table  valign="top" cellpadding="0" cellspacing="0"> 
											<tr valign="top" >
												<th width="90px">차량번호</th>
												<th width="75px">운전자</th>
												<th width="123px">진입시각</th>
												<th width="123px">진출시각</th>
												<th width="*">정차여부</th>
											</tr>
												
										</table>
									</div><!--chart_head end-->
									<div class="chart_body">
										<table cellpadding="0" cellspacing="0" id="checkAreaHistoryList"> 
											<tr valign="top" >
												<td width="90px" id="car_CarReginumber"></td>
												<td width="75" id="dri_Name"></td>
												<td width="123px" id="entryTime"></td>
												<td width="123px" id="exitTime"></td>
												<td width="*" id="stop"></td>
											</tr>
										</table>	
									</div><!-- chart_body end -->
								</div><!-- chart300 end-->
							</div><!--topRightContent end -->
						</div><!--topLeftAndRightContent end -->
					
					
					</div><!--topRight end -->
					
				</div><!--topLeftAndRight-->
				
				
				<div class="bottomLeftAndRight">
					<div class="bottomLeft">
						<div class="bottomLeftContent">
						<form name="inputForm" id="inputForm">
						<input type="hidden" name="checkAreaCode" id="inputCheckAreaCode">
						<input type="hidden" name="lat" id="inputLat">
						<input type="hidden" name="lng" id="inputLng">
							<table class="content1">							
								<tr>
									<th>관심지역명</th>
									<td><input type="text" size="30" name="name" id="inputName"></td>
								</tr>
								<tr>
									<th>위치</th>
									<td><input type="text" size="45" name="address" id="inputAddress"><a onClick="changeAddress()" style="cursor:pointer;">▶</a></td>
								</tr>
								<tr>
									<th>감지반경</th>
									<td><input type="text" size="10" name="radius" id="inputRadius">m</td>
								</tr>
							</table>
							<div class="smsmargin">SMS 알림설정<span>가입서비스에 따라 추가요금이 발생할 수 있습니다.</span></div>
							<div class="leftAndRight">
								<div class="left">
									<p><input type="checkbox" id="inputSmsNoti1" name="sMSNoti1" value='y'>관심지역 내 정차 시 알림</p>
									<p><input type="checkbox" id="inputSmsNoti2" name="sMSNoti2" value='y'>관심지역 진입 시 알림</p>
									<p><input type="checkbox" id="inputSmsNoti3" name="sMSNoti3" value='y'>관심지역 진출 시 알림</p>
								</div> 
								<div class="right">
									<div class="title">알림 SMS 받을 전화번호</div>
									<div><textarea name="sMSNotiPhoneNum" id="inputSmsNotiPhoneNum"></textarea></div>
									<div class="info"><span>SMS 알림을 받을 핸드폰 번호를 한줄에 한 번호씩 숫자만 입력하세요.</span></div>
								</div>
							</div>
							<div class="buttons "><a class="button1 popup_open">대상그룹 선택</a></div>
							<div class="buttons"><a class="button2" onClick="javascript:updateCheckArea();">수정</a><a class="button2" onClick="javascript:deleteCheckArea();">삭제</a><a class="button2 right" onClick="javascript:registCheckArea();">새 관심지역으로 등록</a></div>
						</form>
						</div>
					</div><!--bottomLeft-->
					<div class="bottomRight" id="map_canvas" style="width:528px;height:300px;">
						
						
					</div><!--bottomRight-->
				</div><!--bottomLeftAndRight-->
	        	
        	
		</div> <!-- mainContent end -->
		</div><!-- m310height end -->
		<div class="chart_footer">
		    <div class="footerCenter">
		       <span>Copyright ⓒ 2013 Qrotech Co.,Ltd. All rights reserved.</span>
		    </div>
	 </div>	<!-- footer end-->		
	<div class="m310_popup_box" id="popup1">
		<div class="tableTitleA ">대상 그룹 선택 (관심지역명)<img class="popup_close" src="${imgUrl}/popup_close.png"></div>
		<div class="content">
			<ul>
				<li>관심지역 진출입 관리를 할 대상 차량을 오른쪽으로 추가합니다.</li>
				<li>관리그룹은 차량관리에서 추가할 수 있습니다.</li>
			</ul>
			
			<div class="wrapper">
					<div class="left">
						<div class="title1">추가가능그룹</div>
						<div class="scroll">
							<table class="content1" id="leftGroup">
								<tr onClick="setLeftCarGroupCode(this)" style="cursor:pointer;">
									<td id="groupName">관리그룹 1</td>
									<td style="display:none;"><input type="hidden" id="carGroupCode"></td>
								</tr>
								
							</table>
						</div>
					</div>
					<div class="middle">
						<p><a class="button2" onClick="addGroup()">추가 ></a></p>
						<p><a class="button2" onClick="deleteGroup()">&lt; 제외</a></p>
					</div>
					<div class="right">
						<div class="title2">추가된 그룹</div>
						<div class="scroll">
							<table class="content1 space" id="rightGroup">
								<tr onClick="setRightCarGroupCode(this)" style="cursor:pointer;">
									<td id="groupName">미지정</td>
									<td style="display:none;"><input type="hidden" id="carGroupCode"></td>
								</tr>
							</table>
						</div>
					</div>
			</div>
			<div class="Rowbtn2"><a class="button2" onClick="closePopup();">확인</a><a class="button2 last" onClick="closePopup();">취소</a></div>
		</div><!-- content end-->	
	</div>	<!--groupManage_popup_box-->
	<script language="javascript">
		var _this = this;
		function init(){
			getCheckAreaList();
			initialize();
		}
		function getCheckAreaList() {
			_this.table1 = tableSync('checkAreaList');
			try{				
	    		var url="getCheckAreaList.json";
	    		var param = "checkAreaCode=0";
	    		AjaxPost(url, param, function(data){
	    			 //jsonLog(data.checkAreaList);
	    			 if (data.checkAreaList.length > 0) {
	    				$(data.checkAreaList).each(function(ind) {
	    					this['noti'] = "";
	    					var time = this['modifyDate'];
	    					if (time != '') {
								this['modifyDate'] = formatter.dateFormatYYYYMMDD(new Date(time));
	    					}
							if(this['smsnoti1'] == 'y' || this['smsnoti2'] == 'y' || this['smsnoti3'] == 'y') {
								this['noti'] = "알림";
							}
							
							this['radius'] = this['radius']+"m";
	    				});
	    				_this.table1.tableAutoSync(data.checkAreaList);	
	    				selectedCheckbox();
	    			 }
	    		});
	    		getGroup(0);
	    	}catch(e){
	    		//logs(e);
	    	}
		} 
		function selectedCheckbox() {
			$("#checkAreaList > tbody > tr").each(function() {
				if($(this).find("#useYn").val() == 'y') {
					$(this).find("#use").prop('checked', true);
				}	
			});
		}
		function setData(tr) {
			clearData();
			var checkAreaCode = $(tr).find('#checkAreaCode').val();
			$('#inputCheckAreaCode').val(checkAreaCode);
			getCheckAreaInfo(checkAreaCode);
			//getCheckAreaHistoryList(checkAreaCode);
		}
		
		function clearData() {
			/* $('#inputCheckAreaCode').val("");
			$('#inputName').val("");
			$('#inputAddress').val("");
			$('#inputRadius').val("");
			
			$("input[name='sMSNoti1']").prop("checked", "");
			$("input[name='sMSNoti2']").prop("checked", "");
			$("input[name='sMSNoti3']").prop("checked", "");
			$('#inputSmsNotiPhoneNum').val(""); */
			
			$('#inputForm')[0].reset();
		}
		function getCheckAreaHistoryList(checkAreaCode) {
			_this.table1 = tableSync('checkAreaHistoryList');
			try{
	    		var url="getCheckAreaHistoryList.json";
	    		var param = "checkAreaCode="+checkAreaCode;
	    		AjaxPost(url, param, function(data){
// 	    			 jsonLog(data.checkAreaHistoryList);
	    			 if (data.checkAreaHistoryList.length > 0) {
	    				$(data.checkAreaHistoryList).each(function(ind) {
	    					var entryTime = this['entryTime'];
	    					if (entryTime != '') {
								this['entryTime'] = formatter.dateFormatYYMMDDHHMM(new Date(entryTime));
	    					}
	    					var exitTime = this['exitTime'];
	    					if (exitTime != '') {
								this['exitTime'] = formatter.dateFormatYYMMDDHHMM(new Date(exitTime));
	    					}
	    					
							if(this['stop'] == 'y') {
								this['stop'] = "정차";
							} else {
								this['stop'] = "통과";
							}
	    				});
	    				_this.table1.tableAutoSync(data.checkAreaHistoryList);
	    			 }
	    		});
	    		
	    	}catch(e){
	    		//logs(e);
	    	}
		}
		
		function getCheckAreaInfo(checkAreaCode) {
			try{
	    		var url="getCheckAreaInfo.json";
	    		var param = "checkAreaCode="+checkAreaCode;
	    		AjaxPost(url, param, function(data){
	    			 //jsonLog(data.checkAreaInfo);
	    			 if (data.checkAreaInfo != null) {
	    					$('#inputName').val(data.checkAreaInfo['name']);
	    					$('#inputAddress').val(data.checkAreaInfo['address']);
	    					gMapCodeAddress(data.checkAreaInfo['address']);
	    					
	    					if(data.checkAreaInfo['radius'] < 20) {
	    						$('#inputRadius').val(20);
	    					} else {
		    					$('#inputRadius').val(data.checkAreaInfo['radius']);
	    					}
	    					
	    					if(data.checkAreaInfo['smsnoti1'] == 'y') {
	    						$("input[name='sMSNoti1']").prop("checked", "checked");
	    					}
	    					if(data.checkAreaInfo['smsnoti2'] == 'y') {
	    						$("input[name='sMSNoti2']").prop("checked", "checked");
	    					}
	    					if(data.checkAreaInfo['smsnoti3'] == 'y') {
	    						$("input[name='sMSNoti3']").prop("checked", "checked");
	    					}
	    					
	    					$('#inputSmsNotiPhoneNum').val(data.checkAreaInfo['smsnotiPhoneNum']);
	    			 }
	    			 
	    			 if (data.checkAreaHistoryList.length > 0) {
	    				    _this.table1 = tableSync('checkAreaHistoryList');
		    				$(data.checkAreaHistoryList).each(function(ind) {
		    					var entryTime = this['entryTime'];
		    					if (entryTime != '') {
									this['entryTime'] = formatter.dateFormatYYMMDDHHMM(new Date(entryTime));
		    					}
		    					var exitTime = this['exitTime'];
		    					if (exitTime != '') {
									this['exitTime'] = formatter.dateFormatYYMMDDHHMM(new Date(exitTime));
		    					}
		    					
								if(this['stop'] == 'y') {
									this['stop'] = "정차";
								} else {
									this['stop'] = "통과";
								}
		    				});
		    				_this.table1.tableAutoSync(data.checkAreaHistoryList);
		    			 }
	    			
	    		});
				getGroup(checkAreaCode);
	    		
	    	}catch(e){
	    		//logs(e);
	    	}
		}
		
		function updateCheckArea() {
			var checkAreaCode = $('#inputCheckAreaCode').val();
			if (checkAreaCode == '') {
				alert('관심지역을 선택하세요');
				return;
			}
			var url = "updateCheckArea.json";
			var param = {};
			
			var name = $('#inputName').val();
			var lat = $('#inputLat').val();
			var lng = $('#inputLng').val();
			var address = $('#inputAddress').val();
			var radius = $('#inputRadius').val();
			var smsnoti1 = $("input[name=sMSNoti1]:checkbox:checked").val();
			var smsnoti2 = $("input[name=sMSNoti2]:checkbox:checked").val();
			var smsnoti3 = $("input[name=sMSNoti3]:checkbox:checked").val();
			var smsnotiphonenum = $('#inputSmsNotiPhoneNum').val();
			
			if (smsnoti1 == '' || smsnoti1 == null) smsnoti1 = 'n';
			if (smsnoti2 == '' || smsnoti2 == null) smsnoti2 = 'n';
			if (smsnoti3 == '' || smsnoti3 == null) smsnoti3 = 'n';
			
			//알림이 체크 되었다면 SMS 전화번호는 필수
			if(smsnoti1 == 'y' || smsnoti2 == 'y' || smsnoti3 == 'y') {
				if(smsnotiphonenum == '') {
					alert('전화번호를 입력하세요');
					$('#inputSmsNotiPhoneNum').focus();
					return;
				}
			}
			param['checkAreaCode'] = checkAreaCode;
			param['name'] = name;
			param['lat'] = lat;
			param['lng'] = lng;
			param['address'] = address;
			param['radius'] = radius;
			param['SMSNoti1'] = smsnoti1;
			param['SMSNoti2'] = smsnoti2;
			param['SMSNoti3'] = smsnoti3;
			param['SMSNotiPhoneNum'] = smsnotiphonenum.replace("\r\n","<br>");
			
			AjaxPost(url, param, function(data){
				alert(data.msg);
				getCheckAreaList();
				
				var carGroupCode = "";
				$('#rightGroup tr').each(function() {
					carGroupCode += $(this).find('#carGroupCode').val() + ":" ;
				});
				registGroup('',0,carGroupCode,checkAreaCode);
			});
			
			
		}
		
		function registCheckArea() {
			var url = "registCheckArea.json";
			var param = {};
			
			var name = $('#inputName').val();
			var lat = $('#inputLat').val();
			var lng = $('#inputLng').val();
			var address = $('#inputAddress').val();
			var radius = $('#inputRadius').val();
			var smsnoti1 = $("input[name=sMSNoti1]:checkbox:checked").val();
			var smsnoti2 = $("input[name=sMSNoti2]:checkbox:checked").val();
			var smsnoti3 = $("input[name=sMSNoti3]:checkbox:checked").val();
			var smsnotiphonenum = $('#inputSmsNotiPhoneNum').val();
			var modifyDateDT = new Date().getTime();
			modifyDateDT = parseInt(modifyDateDT/1000);
			
			if(name == '' || name == null) {
				alert('관심지역을 등록하세요.');
				return;
			}
			
			var carGroupCode = "";
			$('#rightGroup tr').each(function() {
				carGroupCode += $(this).find('#carGroupCode').val() + ":" ;
			});
			if(carGroupCode == "") {
				alert('관심그룹을 선택하세요.');
				return;
			}
			if (smsnoti1 == '' || smsnoti1 == null) smsnoti1 = 'n';
			if (smsnoti2 == '' || smsnoti2 == null) smsnoti2 = 'n';
			if (smsnoti3 == '' || smsnoti3 == null) smsnoti3 = 'n';
			
			param['name'] = name;
			param['lat'] = lat;
			param['lng'] = lng;
			param['address'] = address;
			param['radius'] = radius;
			param['SMSNoti1'] = smsnoti1;
			param['SMSNoti2'] = smsnoti2;
			param['SMSNoti3'] = smsnoti3;
			param['SMSNotiPhoneNum'] = smsnotiphonenum.replace("\r\n","<br>");
			param['modifyDateDT'] = modifyDateDT;
			
			AjaxPost(url, param, function(data){
				registGroup(name, modifyDateDT, carGroupCode, 0);
				alert(data.msg);
				getCheckAreaList();
// 				document.location.reload();
			});
			
		}
		
		function deleteCheckArea() {
			var checkAreaCode = $('#inputCheckAreaCode').val();
			if (checkAreaCode == '') {
				alert('관심지역을 선택하세요');
				return;
			}
			
			if(!confirm('관심지역의 진출입 히스토리도 삭제되어 다시 조회할수 없게 됩니다.\n계속 삭제하시겠습니까?')) {
				return;
			}
			
			var url = "deleteCheckArea.json";
			var param = "checkAreaCode="+checkAreaCode;
			AjaxPost(url, param, function(data){
				alert(data.msg);
				document.location.reload();
			});
		}
		
		function updateUseYN(chk) {
			var useYn = 'n';
			var checkAreaCode = $(chk).parent().parent().find("#checkAreaCode").val();
			if ($(chk).is(":checked")) {
				useYn = $(chk).val();
			}
			try{
	    		var url="updateUseYN.json";
	    		var param = "checkAreaCode="+checkAreaCode+"&useYn="+useYn;
	    		AjaxPost(url, param, function(data){
    				 alert(data.msg);
	    		});
	    	}catch(e){
	    		//logs(e);
	    	}
		}
		function getGroup(checkAreaCode) {
			
			var url="getGroup.json"; 
    		var param = "checkAreaCode="+checkAreaCode;
    		var rtnVal = "";
    		AjaxPost(url, param, function(data){
    			 if(data.leftGroup.length > 0) {
					 _this.table1 = tableSync('leftGroup');
					 _this.table1.tableAutoSync(data.leftGroup);
				 }
    			 if(checkAreaCode > 0) {
					 _this.table1 = tableSync('rightGroup');
					 _this.table1.tableAutoSync(data.rightGroup);
					 if(data.rightGroup.length == 0) {
    					 rtnVal += "<tr id='noGroup' onClick='setRightCarGroupCode(this)' style='cursor:pointer;'>";
						 rtnVal += 		"<td id='groupName'>미지정</td>";
						 rtnVal += 		"<td style='display:none;''><input type='hidden' id='carGroupCode' value='0'></td>";
						 rtnVal += "</tr>";
						 $('#rightGroup').html(rtnVal);
    				 }
    			 }
    		});			 
		}
		var leftSelectedTr = null, rightSelectedTr = null;
		function setLeftCarGroupCode(tr){
			if(tr != null) {
				$(leftSelectedTr).find("td").css("background-color","white");
				$(tr).find("td").css("background-color","grey");
				leftSelectedTr = tr;
			}
		}
		
		function setRightCarGroupCode(tr){
			if (tr != null) {
				$(rightSelectedTr).find("td").css("background-color","white");
				$(tr).find("td").css("background-color","grey");
				rightSelectedTr = tr;
			}
		}
		
		function addGroup() {
			$(leftSelectedTr).remove();
			$(leftSelectedTr).find("td").css("background-color","white");
			$('#rightGroup').append($(leftSelectedTr).attr("onClick", "setRightCarGroupCode(this)"));
			$('#noGroup').remove();
		}
		
		function deleteGroup() {
			$(rightSelectedTr).remove();
			$(rightSelectedTr).find("td").css("background-color","white");
			if($(rightSelectedTr).find("#groupName").text() != "미지정") {
				$('#leftGroup').append($(rightSelectedTr).attr("onClick", "setLeftCarGroupCode(this)"));
			}
		}
		
		function registGroup(name, modifyDateDT, carGroupCode, checkAreaCode) {
			
			if(checkAreaCode == 0) { //등록
				//checkAreaCode를 name과 modifyDateDT로 가져온다.
				try{
		    		var url="getCheckAreaCode.json";
		    		var param = "name="+name+"&modifyDateDT="+modifyDateDT;
		    		AjaxPost(url, param, function(data){
		    			checkAreaCode = data.checkArea['checkAreaCode'];
		    			var lastIndex = carGroupCode.lastIndexOf(':');
						carGroupCode = carGroupCode.substr(0,lastIndex);
						
			    		url="registGroup.json";
			    		param = "checkAreaCode="+checkAreaCode+"&carGroupCodeStr="+carGroupCode;
			    		AjaxPost(url, param, function(data){
			    			getGroup(checkAreaCode);
			    		});
		    		});
		    		
		    	}catch(e){
		    		//logs(e);
		    	}
			} else { //수정
				try {
					var lastIndex = carGroupCode.lastIndexOf(':');
					carGroupCode = carGroupCode.substr(0,lastIndex);
					
		    		url="registGroup.json";
		    		param = "checkAreaCode="+checkAreaCode+"&carGroupCodeStr="+carGroupCode;
		    		AjaxPost(url, param, function(data){
		    			getGroup(checkAreaCode);
		    		});
				} catch(e) {
					
				}
			}
			/* var checkAreaCode = $('#inputCheckAreaCode').val();
			var carGroupCode = "";
			$('#rightGroup tr').each(function() {
				carGroupCode += $(this).find('#carGroupCode').val() + ":" ;
			});
			
			if (checkAreaCode != null && checkAreaCode > 0) {
				
				var lastIndex = carGroupCode.lastIndexOf(':');
				carGroupCode = carGroupCode.substr(0,lastIndex);
				try{
		    		var url="registGroup.json";
		    		var param = "checkAreaCode="+checkAreaCode+"&carGroupCodeStr="+carGroupCode;
		    		AjaxPost(url, param, function(data){
		    			alert(data.msg);
		    		});
		    		
		    	}catch(e){
		    		//logs(e);
		    	}
			}*/
			closePopup(); 
		}
		
		function closePopup(){
			$('#overlay').css('display', 'none');
	       	$('#popup1').hide();
		}
		function changeAddress() {
			gMapCodeAddress($('#inputAddress').val());
		}
		
		var map;
        var selectedMarker;
        var circle;
		function initialize() {
	        var mapOptions = {
	          center: new google.maps.LatLng(37.565262680889965, 126.97311401367188),
	          zoom: 10,
	          minZoom : 3,
	          maxZoom : 17,
	          mapTypeId: google.maps.MapTypeId.ROADMAP
	        };
	        map = new google.maps.Map(document.getElementById("map_canvas"), mapOptions);
	        
	        initBinding();
	      }
	      
	      function initBinding(){
	    	  
	    	  $('#move1').bind('click', function(){
	    		  move1();
	    	  });
	    	  
	    	 /*  $('#zoom3').bind('click', function(){
	  				gMapChangeZoom(13);
	    	  }); */
	    	  
			  $('#gotoAddressPosition').bind('click', function(){
				  gMapCodeAddress($('#setAddress').val());
			  });
	    	  
	    	  
	    	  google.maps.event.addListener(map, 'click', function(event) {
	    		    //map.setZoom(10);
	    		    gMapShowClickedPosition(event.latLng);
	    		  });
	      }
	      var infowindow = new google.maps.InfoWindow();
	      var geocoder = new google.maps.Geocoder();
	      
	      // 클릭된 곳에 마크와 주소 표시
	      function gMapShowClickedPosition(latLng){
	    		    	  
	    	  if(selectedMarker != null || circle != null){
	    		  selectedMarker.setMap(null);
	    		  circle.setMap(null);
	        	  infowindow.open(null, null);  
	    	  }
	    	  var address="", lat = "", lng = "";
	    	  geocoder.geocode({'latLng': latLng}, function(results, status) {
	    	      if (status == google.maps.GeocoderStatus.OK) {
	    	        if (results[0]) {
//	     	          map.setZoom(11);
	    	          selectedMarker = new google.maps.Marker({
	    	              position: latLng,
	    	              map: map
	    	          });
	    	          var inputRadius = $("#inputRadius").val();
	    	          if (inputRadius < 20) {
	    	        	  inputRadius = 20;
	    	          }
	    	          circle = new google.maps.Circle({
	    	        	  map: map,
	    	        	  draggable : false,
	    	        	  editable : false,
	    	        	  clickable : false,
	    	        	  radius : parseInt(inputRadius)
	    	          });
	    	          circle.bindTo('center', selectedMarker, 'position');
	    	          
	    	          address=results[0].formatted_address;
	    	          lat = results[0].geometry.location.lat();
	    	          lng = results[0].geometry.location.lng();
	    	          infowindow.setContent(address.replace("대한민국", ""));
	    	          infowindow.open(map, selectedMarker);
	    	          
	    	          gMapSetAddress(address, lat, lng);// ajax 통신이기 때문에 이 곳에서 해야 한다.
	    	        }
	    	      } else {
	    	        alert("Geocoder failed due to: " + status);
	    	      }
	    	    });	
	    	  
	      }
	      
	      
	      // 입력된 주소로 이동
	      function gMapCodeAddress(address) {

	    	  
	    	  if(selectedMarker != null){
	    		  selectedMarker.setMap(null);
	        	  infowindow.open(null, null);  
	    	  }
	    	    geocoder.geocode( { 'address': address}, function(results, status) {
	    	      if (status == google.maps.GeocoderStatus.OK) {
	    	        map.setCenter(results[0].geometry.location);
	    	        gMapShowClickedPosition(results[0].geometry.location);
	    	      } else {
	    	        alert("Geocode was not successful for the following reason: " + status);
	    	      }
	    	    });
	    	  }
	      
	      // 주소 넣기.
	      function gMapSetAddress(address, lat, lng){
	    	  address = address.replace("대한민국","");
	    	  $('#inputAddress').val(address);
	    	  $('#inputLat').val(lat);
	    	  $('#inputLng').val(lng);
	      }
	      
	      function move1(){
	    	  gMapGotoPosition(37.397866,126.846443);
	      }
	      
	      // 지도 위치 이동하기.
	      function gMapGotoPosition(lat, lng){
	    	  var pos = new google.maps.LatLng(lat,lng);
				map.setCenter(pos);
	      }
	      
	      //지도 줌 변경
	      function gMapChangeZoom(zoom){
	    	  map.setZoom(zoom);
	      }
	</script>
  </body>
</html>
